<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #btn:focus {
            background-color: red;
        }
    </style>
</head>

<body>
    <button id="btn" onclick="test()">test</button>
    <script>
        const btn = document.getElementById('btn')
        const event = document.createEvent('MouseEvent')
        event.initEvent('click', true, true)
        btn.dispatchEvent(event)
        function test() {
            alert('fcuk you')
        }
    </script>
</body>

</html>